package com.qzsoft.zhjd.server.modules.asphalt.service.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.qzsoft.zhjd.server.modules.asphalt.service.CollectAsphaltMatchTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;

import com.qzsoft.zhjd.server.modules.asphalt.entity.CollectAsphaltMatchTypeEntity;
import com.qzsoft.zhjd.server.modules.asphalt.mapper.CollectAsphaltMatchTypeMapper;

/**
 * @ClassName AsphaltMatchTypeServiceImpl
 * @Description 配方类型业务接口实现
 * @author linhuawei
 * @since 2022-02-09
 */
@Service
public class CollectAsphaltMatchTypeServiceImpl implements CollectAsphaltMatchTypeService {

    @Autowired
    private CollectAsphaltMatchTypeMapper collectAsphaltMatchTypeMapper;

    @Override
    public Set<String> getSieveSetByType(String matchType) {
        if (ObjectUtils.isEmpty(matchType)) {
            return null;
        }

        // 获取配方类型信息
        QueryWrapper<CollectAsphaltMatchTypeEntity> queryWrapper = new QueryWrapper<CollectAsphaltMatchTypeEntity>();
        queryWrapper.eq("type", matchType);
        List<CollectAsphaltMatchTypeEntity> list = collectAsphaltMatchTypeMapper.selectList(queryWrapper);
        if (null == list || 1 != list.size()) {
            return null;
        }

        // 获取筛孔配置（json数组格式的字符串）
        String text = list.get(0).getSieveArray();
        if (null != text) {
            try {
                JSONArray array = JSONArray.parseArray(text);
                Set<String> result = new HashSet<String>();
                for (int i = 0, len = array.size(); i < len; i++) {
                    if (null != array.getBigDecimal(i)) {
                        result.add(array.getBigDecimal(i).stripTrailingZeros().toPlainString());
                    }
                }
                return result;
            } catch (Exception e) {
            }
        }

        return null;
    }

}
